#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

const int  MAX_SIZE = 3;

typedef struct Stack{
    int item[MAX_SIZE];
    int top;
}Stack;


Stack* init(){
    Stack *s = (Stack* )malloc(sizeof(Stack));
    if(s == NULL){
        printf("error assgin! \n");
        exit(1);
    }
    s->top = -1;
    return s;
}

bool isEmpty(Stack* stack){
    return stack->top == -1;
}

bool isFull(Stack* stack){
    return stack->top == MAX_SIZE-1;
}

int size(Stack* s){
    return s->top+1;
}

void push(Stack* stack,int data){
    if(isFull(stack)){
        printf("栈已经满了\n");
        return;
    }
    stack->item[++stack->top] = data; 
}


int pop(Stack* stack){
    if(isEmpty(stack)){
        printf("栈是空的 无法出栈\n");
        return -1;
    }
    return stack->item[stack->top--];
}


int peek(Stack* stack){
    if(isEmpty(stack)){
        printf("空的无法查看！\n");
        return -1;
    }
    return stack->item[stack->top];
}


int main(){
    Stack* s = init();
    push(s,10);
    push(s,20);
    push(s,30);
    printf("%d \n",peek(s));
    printf("%d \n",pop(s));
    printf("%d \n",pop(s));
    printf("%d \n",pop(s));
}